/**
 * uview 路由拦截器
 */

import authConfig from '@/libs/config/auth.config.js'
import routes from '@/libs/routes/index.js'

const install = function(Vue) {
	uni.$u.routeIntercept = function(mergeConfig, next){
		// console.log(mergeConfig)
		const currentRouteInfo = routes[mergeConfig.url]
		// console.log(currentRouteInfo)
        
		if(currentRouteInfo){
			
			// 判断登录
			if(currentRouteInfo.requiresAuth ? !uni.$u.vuex.getters('user/hasLogin') : false){
				uni.$u.func.hasLoginTask(() => {}, uni.$t('login.routerOutTips'))
				return next(false)
			}
			// 判断权限
			// if(Array.isArray(currentRouteInfo.permissions)){
				// 这里需要自定义处理业务逻辑，用于获取用户的权限代码
			//  const accountPermissions = uni.$ue.vuex.get('user.permissions')
			// 	currentRouteInfo.permissions.some(needCode => {
			// 		// 这里把子权限转换为数组
			// 		needCode = needCode.slice('.')
			// 		for(let code in needCode){
						
			// 		}
			// 	})
			// }
			
		}
		next(true)
	}
}

export default {
	install
}
